<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>新增</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/index.css">
    <script type="text/javascript" src="/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/index.js"></script>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/layui-post.js"></script>
    <script type="text/javascript" src="/js/xcity.js"></script>
    <script type="text/javascript" src="/verify.js"></script>
</head>
<style type="text/css">
    .layui-col-md6{margin-bottom: 10px;}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form layui-form-pane" lay-filter="editForm" id="edit">
            <div class="layui-card-body ">
                <div class="layui-tab layui-tab-card">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">产品类型</label>
                            <div class="layui-input-block">
                                <select name="productType" id="productType" lay-verify="required"><option value="">请选择产品类型</option></select>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">商品名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="goodsName" autocomplete="off" placeholder="请输入商品名称" lay-verify="required" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">商品价格</label>
                            <div class="layui-input-block">
                                <input type="number" name="goodsPrice" autocomplete="off" placeholder="请输入商品价格" lay-verify="required" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">商品折扣</label>
                            <div class="layui-input-block">
                                <input type="number" name="discount" autocomplete="off" lay-verify="required|numminmax" lay-title="商品折扣" lay-min="0" lay-max="10" placeholder="请输入商品折扣" value="10" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">商品类型</label>
                            <div class="layui-input-block">
                                <select name="goodsType" id="goodsType" lay-verify="required"></select>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">商品份量</label>
                            <div class="layui-input-block">
                                <input type="text" name="goodsWeight" autocomplete="off" placeholder="请输入商品份量" lay-verify="required" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">商品海报</label>
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" id="goodsImg"><i class="layui-icon">&#xe67c;</i>上传海报</button>
                                <input style="display:none;width:70%;margin-left:-4px;border-radius:0;box-shadow: 0px 0px 0px 0px;border:none;" type="text" name="goodsImg"  lay-verify="required" value="" placeholder="暂无图片" readonly="readonly" class="layui-input">
                                <div style="display:inline-block;margin-left:4px;border-radius:0;box-shadow: 0px 0px 0px 0px;border:none;" id="agoodsImg"></div>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><span class='x-red'>* </span>配送方式</label>
                            <div class="layui-input-block">
                                <select name="deliveryType" id="deliveryType" lay-verify="required"><option value="">请选择配送方式</option></select>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">优惠类型</label>
                            <div class="layui-input-block">
                                <select name="freeType" id="freeType" lay-verify="required"><option value="">请选择优惠类型</option></select>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">剩余库存</label>
                            <div class="layui-input-block">
                                <input type="number" id="goodsStock" name="goodsStock" required="" lay-verify="required|numminmax" lay-title="剩余库存" lay-min="0" lay-max="10000" placeholder="请输入剩余库存" autocomplete="off" class="layui-input" value="10000">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">参与积分</label>
                            <div class="layui-input-block">
                                <select id="isInter" name="isInter" required="" lay-filter="joinInter" lay-verify="required" class="layui-input">
                                    <option value="0">否</option><option value="1">是</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-md6 isShowJoinInter" style="display: none;">
                            <label class="layui-form-label layui-required">积分数量</label>
                            <div class="layui-input-block">
                                <input type="number" name="interNum" id="interNum" autocomplete="off" placeholder="请输入积分数量" lay-verify="required" value="0" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">是否置顶</label>
                            <div class="layui-input-block">
                                <select id="isTop" name="isTop" required="" lay-verify="required" class="layui-input">
                                    <option value="0">否</option><option value="1">是</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-md12">
                            <label class="layui-form-label layui-required">商品主料</label>
                            <div class="layui-input-block">
                                <textarea class="layui-input" name="goodsMain" lay-verify="required" placeholder="请输入商品主料" style="height: 100px;"></textarea>
                            </div>
                        </div>
                        <div class="layui-col-md12">
                            <label class="layui-form-label layui-required">商品说明</label>
                            <div class="layui-input-block">
                                <textarea class="layui-input" name="remark" lay-verify="required" placeholder="请输入商品说明" style="height: 100px;"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" type="button" lay-filter="add" lay-submit="" id="submit">保存</button>
            </div>
        </form>
    </div>
</div>
<script>
$.ajaxSetup({contentType: "application/json; charset=utf-8"});
layui.use(['form','layer','laydate','layedit','upload'], function(){
    var form = layui.form,layer = layui.layer,upload = layui.upload,textInit;
    var uploadInst = upload.render({
        elem: '#goodsImg', //绑定元素
        url: '/ueditor/uploadFile', //上传接口
        accept: 'file',
        multiple: false,
        exts:'pdf|jpg|jpeg|png',
        data:{type:4},
        done: function(res){
            $('input[name="goodsImg"]').val(res.fileName)
            $("#agoodsImg").html('<a href="#" style="color:blue;" onclick="showpic(\''+res.fileName+'\',60,80)" title="预览">预览<i class="layui-icon">&#xe615;</i></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="cleardata(\'goodsImg\',\''+res.fileName+'\',\'0\')">清空<i class="layui-icon layui-icon-close"></i></a><br>');
        }
    });
    $.post(geturl()+'/enums/select?token='+sessionStorage.getItem("token"), JSON.stringify({parentEnumCode:"PRODUCT_TYPE<->FREE_TYPE<->DELIVERY_TYPE<->GOODS_TYPE",orderByAscType:"enumCode"}), function (res) {
        for(var key in res.data.PRODUCT_TYPE) $('#productType').append('<option value="'+key + '">' + res.data.PRODUCT_TYPE[key] + '</option>');
        for(var key in res.data.FREE_TYPE) $('#freeType').append('<option value="'+key + '">' + res.data.FREE_TYPE[key] + '</option>');
        for(var key in res.data.DELIVERY_TYPE) $('#deliveryType').append('<option value="'+key + '">' + res.data.DELIVERY_TYPE[key] + '</option>');
        for(var key in res.data.GOODS_TYPE) $('#goodsType').append('<option value="'+key + '">' + res.data.GOODS_TYPE[key] + '</option>');
        layui.form.render();
    }).done(function(){
        $.post(geturl()+'/cateringGoods/select?token='+sessionStorage.getItem("token"), JSON.stringify({sysId:getQueryString("sysId")}), function (res) {
            for(var i in res.data){
                form.val("editForm", {
                    "freeType": res.data[i].freeType,
                    "productType": res.data[i].productType,
                    "goodsImg": res.data[i].goodsImg,
                    "goodsType": res.data[i].goodsType,
                    "deliveryType": res.data[i].deliveryType,
                    "discount": res.data[i].discount,
                    "goodsName": res.data[i].goodsName,
                    "goodsPrice": res.data[i].goodsPrice,
                    "goodsMain": res.data[i].goodsMain,
                    "goodsWeight": res.data[i].goodsWeight,
                    "goodsStock": res.data[i].goodsStock,
                    "isInter": res.data[i].isInter,
                    "interNum": res.data[i].interNum,
                    "isTop": res.data[i].isTop,
                    "integralNum": res.data[i].integralNum,
                    "remark": res.data[i].remark,
                });
                if(!isEmpty(res.data[i].goodsImg)) $("#agoodsImg").html('<a href="#" style="color:blue;" onclick="showpic(\''+res.data[i].goodsImg+'\',60,80)" title="预览">预览<i class="layui-icon">&#xe615;</i></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="cleardata(\'goodsImg\',\''+res.data[i].goodsImg+'\',\'0\')">清空<i class="layui-icon layui-icon-close"></i></a><br>');
                layui.form.render();
                textInit = JSON.stringify({ dataform: $("#edit").serializeArray() });
            }
        }, 'json');
    })
    //监听提交
    layui.form.on('submit(add)', function(data){
        data.field.sysId = getQueryString("sysId")
        var text = JSON.stringify({ dataform: $("#edit").serializeArray() });
        if(textInit == text) {
            layui.use('layer',function(){
                layer.msg("没有更改无需提交!",{icon:5,time:1000});
            })
        }else layuiPost(geturl()+'/cateringGoods/update?token='+sessionStorage.getItem("token"),data.field,parent.layer.getFrameIndex(window.name));
        return false;
    });
});
</script>
</body>
</html>